{% include 'header.html' %}
<script src="https://unpkg.com/@tailwindcss/browser@4"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
<div class="container mx-auto p-4">
    <h1 class="text-2xl font-bold mb-4">交易记录</h1>
    <table class="layui-table" id="backtestRecordTable"></table>
</div>

<script>
    layui.use(['table'], function () {
        var table = layui.table;
        var urlParams = new URLSearchParams(window.location.search);
        var stock = urlParams.get('stock');
        var start_date = urlParams.get('start_date');
        var end_date = urlParams.get('end_date');

        $.ajax({
            url: '/recalltest/get_backtest_records',
            type: 'GET',
            data: {
                stock: stock,
                start_date: start_date,
                end_date: end_date
            },
            success: function (res) {
                if (res.code === 0) {
                    var dataLength = res.data.length;
                    table.render({
                        elem: '#backtestRecordTable',
                        data: res.data,
                        cols: [[
                            {field: 'id', title: 'ID'},
                            {field: 'stock', title: '交易股票'},
                            {field: 'quantity', title: '交易数量'},
                            {field: 'price', title: '交易价格'},
                            {field: 'type', title: '交易类型'},
                            {field: 'timestamp', title: '交易时间'},
                            {field: 'backtest_start', title: '回溯开始日期'},
                            {field: 'backtest_end', title: '回溯结束日期'}
                        ]],
                        limit: dataLength
                    });
                } else {
                    layer.msg(res.msg);
                }
            }
        });
    });
</script>
{% include 'footer.html' %}